package cn.dw.sg.mapper.impl;

import java.util.ArrayList;
import java.util.List;


import cn.dw.sg.domain.Menu;
import cn.dw.sg.mapper.MenuMapper;
import cn.dw.sg.utils.JdbcUtil;

public class MenuMapperImpl implements MenuMapper{

	@Override
	public void add(Menu menu) {
		
		//jdbc方式
		String sql = "insert into menu(business_name,parent_role) values('"+
				menu.getBusinessName() +"',"+menu.getParentId()+")";
		JdbcUtil.excute(sql);
	}

	@Override
	public void update(Menu menu) {
		//jdbc方式
		String sql = "update menu set business_name='"+ menu.getBusinessName() 
		+"', parent_role="+menu.getParentId()+" where id = " + menu.getId();
		JdbcUtil.excute(sql);
	}

	@Override
	public void delete(int id) {
		//jdbc方式
		String sql = "delete from menu where id = " + id;
		JdbcUtil.excute(sql);
	}

	@Override
	public List<Menu> query(Menu menu) {
		String sql = "select * from menu ";
		List<Object> results = JdbcUtil.excuteQuery(sql,Menu.class);
		List<Menu> lists = new ArrayList<>();
		for(Object b : results) {
			Menu temp = (Menu)b;
			lists.add(temp);
		}
		return lists;
	}
 
}
